package DBTasks;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class Login extends DBTask {
    public static boolean login(int empNum, String shelterName, String password){
        if(con == null){
            connectToDatabase();
        }
        
        String queryString = "SELECT Password, Shelter_Name FROM Employee WHERE Employee_Num = ?";
        try {
            PreparedStatement query = con.prepareStatement(queryString);
            query.setInt(1, empNum);
            ResultSet rs = query.executeQuery();
            rs.first();
            String correctName = rs.getString("Shelter_Name");
            String correctPassword = rs.getString("Password");
            
            return shelterName.equals(correctName) && password.equals(correctPassword);
        }
        catch (SQLException e) {
            e.printStackTrace();
            return false;
        }
    }
}
